import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  optimizeDeps: {
    include: ['axios'],
  },  
  build: {
    target: 'modules',
    outDir: 'dist',
    assetsDir: 'assets',
    minify: 'terser' // 混淆器
  },  
  server:{
    cors: true,
    open: false,
    port: '3000',
    proxy:{
      '/api':{
        target: 'http://127.0.0.1:80', //需要代理的后端地址，代理接口
        changeOrigin: true, //改善请求头中host会设置成target,
        rewrite: (path) => path.replace(/^\/api/, '')  //用此行正确，用下行没把/api替换掉，打不到服务器接口
        // pathRewrite: {'^/api': ''}  //此句的作用是：正则表达式替换^/api为空，这样保证传到后台的不带/api
      }
    }
  }
})
